package com.hiwhitley.easy.day25;

import java.util.HashSet;
import java.util.Iterator;

/**
 * Created by hiwhitley on 2016/10/20.
 */
public class SingleNumber_260 {
    public int[] singleNumber(int[] nums) {
        if(nums.length <= 2)
            return nums;
        HashSet<Integer> hashSet = new HashSet<>();
        for (int val : nums) {
            if (hashSet.contains(val))
                hashSet.remove(val);
            else
                hashSet.add(val);
        }

        int[] result = new int[2];

        Iterator<Integer> iterator = hashSet.iterator();
        result[0] = iterator.next();
        result[1] = iterator.next();
        return result;
    }

    public static void main(String[] args) {
        SingleNumber_260 main = new SingleNumber_260();
        System.out.println(main.singleNumber(new int[]{1, 2, 1, 3, 4, 3}));
    }
}
